#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/5/19 19:24
# @Author : 鲍盈廷
# @File : change_bool.py
import random
import json


# -----------将输入的参数转换bool类型---------------------
def change_bool(bool):
    """
    :param bool: 入参，false,true
    :return: 返回入参相同的布尔类型
    """
    data = bool
    isTrue = data == 'true'
    return isTrue


# -----------将输入的字符串false/true转换成数据库对应的0/1---------------------
def change_num(str):
    if str == 'false':
        return "0"
    else:
        return "1"


# -----------将component_body_type PAGE/NAVIGATION转换成数据库对应的（1：微页，2：店铺导航）---------------------
def change_component_body_type(componentBodyType):
    if componentBodyType == 'PAGE':
        return "1"
    elif componentBodyType == 'NAVIGATION':
        return "2"
    else:
        return "1"


# 同上转化数据。在线常规课：ONLINE_NORMAL 在线试听课：ONLINE_ACTIVITY
def change_type(componentBodyType):
    if componentBodyType == '22':
        return "ONLINE_ACTIVITY"
    elif componentBodyType == '21':
        return "ONLINE_NORMAL"
    else:
        return NONE


# 同上转化数据。在线常规课：PUBLIC 在线试听课：COMMON
def change_curriculumType(curriculumType):
    if curriculumType == 'PUBLIC':
        return 22
    elif curriculumType == 'COMMON':
        return 21
    else:
        return NONE


# 同上转化数据。在线常规课：PUBLIC 在线试听课：COMMON
def change_curriculumType_str(curriculumType):
    if curriculumType == '22':
        return 'PUBLIC'
    elif curriculumType == '21':
        return 'COMMON'
    else:
        return NONE


# ------同上转化数据，课程上架和下架-------
def change_ifsell(if_sell):
    if if_sell == 'PUT_ON':
        return 1
    elif if_sell == 'PUT_DOWN':
        return 0
    else:
        return NONE


# ------同上转化数据，课程上架和下架-------
def change_ifsell_str(if_sell):
    if if_sell == '1':
        return 'PUT_ON'
    elif if_sell == '0':
        return 'PUT_DOWN'
    else:
        return NONE


# ----------根据提取的数据长度，返回长度内的随机整数--------------------
def get_radomnum(data):
    if data == []:
        lens = 0
    else:
        lens = len(data)
    return random.randint(1, lens + 1)


# ------------获取所有的输入字段值，生成列表返回-------------------
def get_radomdata3(datas, str):
    data = [one[str] for one in datas]
    return data


# 获取动态列表接口返回的data字段中的所有id，生成字典{'id':str(one['id'])}结果返回一个列表
def get_id(ones):
    return [{'id': str(one['id'])} for one in ones]


# -----------------课程分组中添加课程，添加多个课程----------------
def add_curriculumTogroup(curriculumGroupId, curriculumIds):
    curriculumId_list = get_radomdata3(curriculumIds, 'id')
    result_data = [{"curriculumGroupId": curriculumGroupId, "curriculumId": f"{one}"} for one in
                   curriculumId_list]
    return json.dumps(result_data)


if __name__ == '__main__':
    print(change_num("false"))